import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;


public class Agent {
	
	private StrategyType stragedy;
	private double totalPayoff;
	private DropOutStack<StrategyType> history;
	
	public DropOutStack<StrategyType> getHistory() {
		return history;
	}

	public void setHistory(DropOutStack<StrategyType> history) {
		this.history = history;
	}
	
	public Agent(StrategyType initialStrategy, int historySize) {
		history = new DropOutStack<StrategyType>(historySize);
		history.push(initialStrategy);
	}

	public Agent(StrategyType stragedy){
		this.stragedy = stragedy;
	}

	public double getThreshold() {
		Iterator<StrategyType> it = history.iterator();
		double cooperations=0;
		
		while (it.hasNext()) {
			if (it.next() == StrategyType.cooperator)
				cooperations++;
		}
		
		if (cooperations != 0)
			return cooperations / history.size();
		else 
			return 0;
	}

	public void pay(double cost){
		this.totalPayoff -= cost;
		}

	public StrategyType getStragedy(){
		return this.stragedy;
	}

	public double getPayoff(){
		return this.totalPayoff;
	}
	
	public void setPayoff(double payoff){
		if(payoff == 0){
			totalPayoff = 0;
		}
		else{
			totalPayoff += payoff;
		}
	}

	public void reward(double payoff){
		this.totalPayoff += payoff;
	}


}
